﻿(function () {
    $paging = window.$paging = function (options) {
        return new $paging.prototype.init(options);
    };
    $paging.prototype = {
        config: {
            doc: null,
            index: 0
        },
        init: function (options) {
            this.config.doc = document.getElementById(options);
            return this;
        },
        createpannel: function (one) {
            var a = document.createElement("div");
            var b = document.createElement("div");
            a.style.width = parseInt(one.style.width) % 2 ==
                0 ? parseInt(one.style.width) / 2 + "px" : Math.ceil(parseInt(one.style.width) / 2) + "px";
            b.style.width = parseInt(one.style.width) % 2 ==
                0 ? parseInt(one.style.width) / 2 + "px" : Math.floor(parseInt(one.style.width) / 2) + "px";
            a.style.height = b.style.height = one.clientHeight;
            var t = one.offsetTop;
            var l = one.offsetLeft;
            while (one = one.offsetParent) {
                t += one.offsetTop;
                l += one.offsetLeft;
            };
            a.style.backgroundColor = b.style.backgroundColor = "#000000";
            a.style.position = b.style.position = "absolute";
            a.style.top = t + "px";
            b.style.top = t + "px";
            a.style.left = l + "px";
            b.style.left = (l + parseInt(a.style.width)) + "px";
            return [a, b];

        },
        go: function (p,obj) {
            var arrobject = p.createpannel(obj);
            for (var i = 0; i < arrobject.length; i++)
            {
                document.body.appendChild(arrobject[i]);
            }
        },
        bind: function () {
            for (var i = 0; i < this.config.doc.childNodes.length; i++) {
                this.bindevent(this.config.doc.childNodes[i], "click", this.go,this, this.config.doc.childNodes[i]);
            }
        },
        bindevent: function (object, type, fn) {
            var temparguments = [].slice.apply(arguments);
            var temparry = [];
            if (temparguments.length > 3) {
                temparry = temparguments.slice(3, temparguments.length);
            }
            if (object.attachEvent) {
                object.attachEvent("on" + type, (function () {
                    return function (event) {
                        window.event.cancelBubble = true;
                        object.attachEvent = [fn.apply(object, temparry)];
                    }
                })(object), false);
            } else if (object.addEventListener) {
                object.addEventListener(type, function (event) {
                    event.stopPropagation();
                    fn.apply(this, temparry)
                });
            }
        }
    };
    $paging.prototype.init.prototype = $paging.prototype;
})();